const App = getApp();
// 工具类
import Util from '../../../utils/util.js';
var WxParse = require('../../../wxParse/wxParse.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isLogin: false,
    teamId: 0,
    cate:1,    //1供应，2需求
    detail:{},
    nid:"",
    phoneShow:false //电话权限
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //设置页面标题
    wx.setNavigationBarTitle({
      title: App.getConfig().company.detail
    })
    this.setData({
      nid:options.nid,
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this;
    that.setData({
      isLogin: App.checkIsLogin(),
    });
    console.log(this.data.nid,this.data.teamId)
    if (that.data.isLogin) {
      that.setData({
        teamId: App.checkTeam(),
      });
      // 获取数据
      that.getDetail();
    }
  },
 // 获取数据
 getDetail() {
    let _this = this;
    let obj = {
      company_id:this.data.nid
    }
    App._get('company/detail', obj, result => {
      console.log("result.data.detail.goods",result.data.detail.goods)
      _this.setData({
        detail: result.data.detail,
        phoneShow:result.data.detail.display==1?true:(_this.data.teamId ==result.data.detail.team_id)?true:false
      })
      WxParse.wxParse('content', 'html', _this.data.detail.company_content, this,5);  
    });
  },
    /**
   * 查看位置
   */
  onOpenLocation() {
    let _this = this,
      detail = _this.data.detail;
    wx.openLocation({
      name: detail.company_name,
      address:detail.address,
      longitude: Number(detail.longitude),
      latitude: Number(detail.latitude),
      scale: 15
    });
  },
//打电话
  tel() {
    let _this = this;
    wx.makePhoneCall({
      phoneNumber: _this.data.detail.phone, //此号码仅用于测试 。
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },
  /**
  * 分享当前页面
  */
 onShareAppMessage() {
   const _this = this;
   return {
     title: _this.data.detail.company_name,
     path: "pages/company/detail/index?nid="+_this.data.nid
   };
 },

 /**
  * 分享到朋友圈
  * 本接口为 Beta 版本，暂只在 Android 平台支持，详见分享到朋友圈 (Beta)
  * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  */
 onShareTimeline() {
   const _this = this;
   return {
    title: _this.data.detail.company_name,
     path: "pages/company/detail/index?nid="+_this.data.nid
   };
 },





})